package com.netposa.task;

import com.netposa.config.GpsConfig;
import com.netposa.service.GpsService;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class GpsImportTask {
   private static Logger logger = Logger.getLogger(GpsImportTask.class);
   @Autowired
   private GpsConfig config;
   @Autowired
   private GpsService gpsService;

   @Scheduled(
      fixedDelayString = "${gps.import.interval}"
   )
   public void fugitiveTask() {
      if (this.config.getOpen()) {
         List gpsModelList = this.gpsService.getGpsInfo();
         byte[] tideDBGpsBytes = this.gpsService.getTideDBGpsBytes(gpsModelList);
         this.gpsService.sendGpsToTideDB(tideDBGpsBytes);
      } else {
         logger.info("Gps信息导入开关未开启!");
      }

   }
}
